Skip to content

Implemented EIP191/712 in clef#17789

Merged
holiman merged 85 commits into
ethereum:masterfrom
PaulRBerg:eip191/712
Feb 6, 2019
Merged

Implemented EIP191/712 in clef#17789
holiman merged 85 commits into
ethereum:masterfrom
PaulRBerg:eip191/712

Conversation

@PaulRBerg
Copy link
Copy Markdown
Contributor

@PaulRBerg PaulRBerg commented Sep 29, 2018

This PR implements EIP-191 and EIP-712.

Additions

  1. Defined a list of content types as per the table below
  2. Written a specific function for each EIP
  3. Implemented the ecRecover method in the clef API

Content Types

This fully respects the EIP-191 specs.

Version byte Name Description
0x00 text/validator Data with intended validator
0x01 data/typed EIP-712 typed data
0x02 application/clique Clique headers
0x45 text/plain Plain, personal messages

Notes

  1. Everything was coded in clef, there will be no work done to retrofit the implementation on geth and eth_sign will be deprecated
  2. Reused the clique functions written by @holiman in the geth_relay branch.

TODO

  • Implement data/typed (EIP712)
  • Write tests for data/typed
  • Implement text/validator
  • Write tests for text/validator

Comment thread signer/core/api.go Outdated
Comment thread signer/core/api.go Outdated
@PaulRBerg
Copy link
Copy Markdown
Contributor Author

The last update also reformatted the code with go fmt.

@holiman
Copy link
Copy Markdown
Contributor

holiman commented Oct 11, 2018

Heh, we usually rebase instead of mega-merge :)

@PaulRBerg
Copy link
Copy Markdown
Contributor Author

Just rebased now :)

@holiman holiman requested review from holiman and removed request for acud, fjl, gbalint, holisticode, janos, karalabe, nolash, nonsense, zelig and zsfelfoldi October 12, 2018 14:57
@PaulRBerg PaulRBerg changed the title [WIP] Implemented EIP191 in clef [WIP] Implemented EIP191/712 in clef Oct 15, 2018
@holiman
Copy link
Copy Markdown
Contributor

holiman commented Feb 5, 2019

Travis finally succeeded. Will merge this later tonight, when I have some time to sit down some more with it and extensively test after the merge

@PaulRBerg
Copy link
Copy Markdown
Contributor Author

Hey @holiman, many thanks for rebasing to the new wallet API :)

But I'm wondering what use there is of ever having that map there...

I originally implemented it like that because I thought it helped with the pretty printing functionality.

Hooray, happy to see Travis passing! Just for the record, is there a known issue with AppVeyor? Afaik, all PRs fail there.

@holiman
Copy link
Copy Markdown
Contributor

holiman commented Feb 6, 2019

Just for the record, is there a known issue with AppVeyor? Afaik, all PRs fail there.

Yup, there is.

@DGideas
Copy link
Copy Markdown

DGideas commented Mar 19, 2025

From https://github.com/ethereum/go-ethereum/pull/17789/files#diff-8e03bbbabe1aac9858b32fe8596aef7c69cfbc6cdbd05a5905d05451b5e42785R385-R388

func (typedData *TypedData) EncodeData(primaryType string, data map[string]interface{}, depth int) (hexutil.Bytes, error) {
...
	// Verify extra data
	if len(typedData.Types[primaryType]) < len(data) {
		return nil, errors.New("there is extra data provided in the message")
	}
...

In the case where a message contains extra fields beyond what the type itself defines, I did some research on this:

  • EIP-712 does not clearly define the detailed rules for retrieving typedData.
  • The Solidity code provided in EIP-712 does not include such a check.
  • The JavaScript example code from the EIP-712 attachments ignores extra fields in the message and still passes.
  • In go-ethereum, the test cases under signer/core/testdata/expfail_* do not contain any failed cases related to extra fields in the message object.

So, I am curious whether this check follows the EIP-712 documentation or if go-ethereum imposes stricter validation than EIP-712 itself. Thanks.

MariusVanDerWijden pushed a commit to MariusVanDerWijden/go-ethereum that referenced this pull request Feb 2, 2026
* Named functions and defined a basic EIP191 content type list

* Written basic content type functions

* Added ecRecover method in the clef api

* Updated the extapi changelog and addded indications in the README

* Changed the version of the external API

* Added tests for 0x45

* Implementing UnmarshalJSON() for TypedData

* Working on TypedData

* Solved the auditlog issue

* Changed method to signTypedData

* Changed mimes and implemented the 'encodeType' function for EIP-712

* Polished docstrings, ran goimports and swapped fmt.Errorf with errors.New where possible

* Drafted recursive encodeData

* Ran goimports and gofmt

* Drafted first version of EIP-712, including tests

* Temporarily switched to using common.Address in tests

* Drafted text/validator and and rewritten []byte as hexutil.Bytes

* Solved stringified address encoding issue

* Changed the property type required by signData from bytes to interface{}

* Fixed bugs in 'data/typed' signs

* Brought legal warning back after temporarily disabling it for development

* Added example RPC calls for account_signData and account_signTypedData

* Named functions and defined a basic EIP191 content type list

* Written basic content type functions

* Added ecRecover method in the clef api

* Updated the extapi changelog and addded indications in the README

* Added tests for 0x45

* Implementing UnmarshalJSON() for TypedData

* Working on TypedData

* Solved the auditlog issue

* Changed method to signTypedData

* Changed mimes and implemented the 'encodeType' function for EIP-712

* Polished docstrings, ran goimports and swapped fmt.Errorf with errors.New where possible

* Drafted recursive encodeData

* Ran goimports and gofmt

* Drafted first version of EIP-712, including tests

* Temporarily switched to using common.Address in tests

* Drafted text/validator and and rewritten []byte as hexutil.Bytes

* Solved stringified address encoding issue

* Changed the property type required by signData from bytes to interface{}

* Fixed bugs in 'data/typed' signs

* Brought legal warning back after temporarily disabling it for development

* Added example RPC calls for account_signData and account_signTypedData

* Polished and fixed PR

* Polished and fixed PR

* Solved malformed data panics and also wrote tests

* Solved malformed data panics and also wrote tests

* Added alphabetical sorting to type dependencies

* Added alphabetical sorting to type dependencies

* Added pretty print to data/typed UI

* Added pretty print to data/typed UI

* signer: more tests for typed data

* signer: more tests for typed data

* Fixed TestMalformedData4 errors and renamed IsValid to Validate

* Fixed TestMalformedData4 errors and renamed IsValid to Validate

* Fixed more new failing tests and deanonymised some functions

* Fixed more new failing tests and deanonymised some functions

* Added types to EIP712 output in cliui

* Added types to EIP712 output in cliui

* Fixed regexp issues

* Fixed regexp issues

* Added pseudo-failing test

* Added pseudo-failing test

* Fixed false positive test

* Fixed false positive test

* Added PrettyPrint method

* Added PrettyPrint method

* signer: refactor formatting and UI

* signer: make ui use new message format for signing

* Fixed breaking changes

* Fixed rules_test failing test

* Added extra regexp for reference types

* signer: more hard types

* Fixed failing test, formatted files

* signer: use golang/x keccak

* Fixed goimports error

* clef, signer: address some review concerns

* Implemented latest recommendations

* Fixed comments and uintint256 issue

* accounts, signer: fix mimetypes, add interface to sign data with passphrase

* signer, accounts: remove duplicated code, pass hash preimages to signing

* signer: prevent panic in type assertions, make cliui print rawdata as quotable-safe

* signer: linter fixes, remove deprecated crypto dependency

* accounts: fix goimport
MariusVanDerWijden pushed a commit to MariusVanDerWijden/go-ethereum that referenced this pull request Feb 2, 2026
* Named functions and defined a basic EIP191 content type list

* Written basic content type functions

* Added ecRecover method in the clef api

* Updated the extapi changelog and addded indications in the README

* Changed the version of the external API

* Added tests for 0x45

* Implementing UnmarshalJSON() for TypedData

* Working on TypedData

* Solved the auditlog issue

* Changed method to signTypedData

* Changed mimes and implemented the 'encodeType' function for EIP-712

* Polished docstrings, ran goimports and swapped fmt.Errorf with errors.New where possible

* Drafted recursive encodeData

* Ran goimports and gofmt

* Drafted first version of EIP-712, including tests

* Temporarily switched to using common.Address in tests

* Drafted text/validator and and rewritten []byte as hexutil.Bytes

* Solved stringified address encoding issue

* Changed the property type required by signData from bytes to interface{}

* Fixed bugs in 'data/typed' signs

* Brought legal warning back after temporarily disabling it for development

* Added example RPC calls for account_signData and account_signTypedData

* Named functions and defined a basic EIP191 content type list

* Written basic content type functions

* Added ecRecover method in the clef api

* Updated the extapi changelog and addded indications in the README

* Added tests for 0x45

* Implementing UnmarshalJSON() for TypedData

* Working on TypedData

* Solved the auditlog issue

* Changed method to signTypedData

* Changed mimes and implemented the 'encodeType' function for EIP-712

* Polished docstrings, ran goimports and swapped fmt.Errorf with errors.New where possible

* Drafted recursive encodeData

* Ran goimports and gofmt

* Drafted first version of EIP-712, including tests

* Temporarily switched to using common.Address in tests

* Drafted text/validator and and rewritten []byte as hexutil.Bytes

* Solved stringified address encoding issue

* Changed the property type required by signData from bytes to interface{}

* Fixed bugs in 'data/typed' signs

* Brought legal warning back after temporarily disabling it for development

* Added example RPC calls for account_signData and account_signTypedData

* Polished and fixed PR

* Polished and fixed PR

* Solved malformed data panics and also wrote tests

* Solved malformed data panics and also wrote tests

* Added alphabetical sorting to type dependencies

* Added alphabetical sorting to type dependencies

* Added pretty print to data/typed UI

* Added pretty print to data/typed UI

* signer: more tests for typed data

* signer: more tests for typed data

* Fixed TestMalformedData4 errors and renamed IsValid to Validate

* Fixed TestMalformedData4 errors and renamed IsValid to Validate

* Fixed more new failing tests and deanonymised some functions

* Fixed more new failing tests and deanonymised some functions

* Added types to EIP712 output in cliui

* Added types to EIP712 output in cliui

* Fixed regexp issues

* Fixed regexp issues

* Added pseudo-failing test

* Added pseudo-failing test

* Fixed false positive test

* Fixed false positive test

* Added PrettyPrint method

* Added PrettyPrint method

* signer: refactor formatting and UI

* signer: make ui use new message format for signing

* Fixed breaking changes

* Fixed rules_test failing test

* Added extra regexp for reference types

* signer: more hard types

* Fixed failing test, formatted files

* signer: use golang/x keccak

* Fixed goimports error

* clef, signer: address some review concerns

* Implemented latest recommendations

* Fixed comments and uintint256 issue

* accounts, signer: fix mimetypes, add interface to sign data with passphrase

* signer, accounts: remove duplicated code, pass hash preimages to signing

* signer: prevent panic in type assertions, make cliui print rawdata as quotable-safe

* signer: linter fixes, remove deprecated crypto dependency

* accounts: fix goimport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants